<!DOCTYPE html>
<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta charset="utf-8">
		<title>业务展示-商品展示</title>
		<meta name="description" content="overview &amp; stats">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
		<!-- bootstrap & fontawesome -->
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/bootstrap.css">
		<link rel="stylesheet" href="${request.contextPath}/static/assets/font-awesome/4.5.0/css/font-awesome.min.css">
		<!-- page specific plugin styles -->
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/daterangepicker.min.css">
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/jquery.css">
		<!-- text fonts -->
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/fonts.css">
		<!-- ace styles -->
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style">
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/ace-skins.min.css">
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/ace-rtl.min.css">
		<!-- ace settings handler -->
		<script src="${request.contextPath}/static/assets/js/ace-extra.min.js"></script><style>@keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}@-moz-keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}@-webkit-keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}@-ms-keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}@-o-keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}.ace-save-state{animation-duration:10ms;-o-animation-duration:10ms;-ms-animation-duration:10ms;-moz-animation-duration:10ms;-webkit-animation-duration:10ms;animation-delay:0s;-o-animation-delay:0s;-ms-animation-delay:0s;-moz-animation-delay:0s;-webkit-animation-delay:0s;animation-name:nodeInserted;-o-animation-name:nodeInserted;-ms-animation-name:nodeInserted;-moz-animation-name:nodeInserted;-webkit-animation-name:nodeInserted}</style>
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/bsie-paginator.css">
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/daterangepicker.css" />
		<script src="${request.contextPath}/static/assets/js/jquery-2.1.4.min.js"></script>
	</head>

	<body class="skin-2" style="background-color: #FFF;">
		<div class="page-content">
			<div class="page-header">
				<h1>
						<!--<i class="ace-icon fa fa-angle-double-right"></i>  --> 
						<#if sceneryName??>${sceneryName}</#if>(<#if prodId??>${prodId}</#if>)
						<input type="hidden" id="prodId" value="<#if prodId??>${prodId}</#if>"/>
						<input type="hidden" id="commodityId" value=""/>
						<input type="hidden" id="_csrf" name="${_csrf.parameterName}" value="${_csrf.token}"/>
				</h1>
				<div class="col-sm-12" align="right">
					<button type="button" class="btn btn-pink btn-sm" onclick="skip('/datashow/show_list?page=<#if pageNum??>${pageNum}<#else>1</#if>')">
						<span class="ace-icon fa icon-on-right bigger-110"></span>
						返回产品页
					</button>
					
				</div>
			</div>
			<div class="row">
				<div class="col-sm-12">
					<div class="row">
						<div class="col-xs-12">
							<div class="tab-pane in active" id="codeList">
								<div id="dynamic-table_wrapper" class="dataTables_wrapper form-inline no-footer">
									<table id="dynamic-table" class="table table-striped table-bordered table-hover dataTable no-footer" role="grid" aria-describedby="dynamic-table_info">
										<thead>
											<tr>
												<th>No.</th>
												<th>商品id</th>
												<th colspan='4'>商品名称</th>
												<!--<th>商品类型</th>-->
												<th>商品价格</th>
												<th>xc</th>
												<th>tn</th>
												<th>tc</th>
												<th>qnr</th>
												<th>详情</th>
												<th>是否设为起价</th>
												<th>历史价格</th>
											</tr>
										</thead>
										<#if tcsvs??&&tcsvs?size&gt;0>
										<#list tcsvs as com>
										<tbody>
												<tr class="center">
													<td>${com_index + 1}</td>
													<td class="tdCommodityId"><#if com.commodity_id??>${com.commodity_id}</#if></td>
													<td colspan='4'><#if com.commodity_name??>${com.commodity_name}</#if></td>
													<td><strong><#if com.sale_price??>${com.sale_price}</#if></strong></td>
													<td><strong>
													 <#if com.sale_price??&&com.sale_price_xc??&&(com.sale_price_xc?number>com.sale_price?number)>
													 <div style="color:green">${com.sale_price_xc}↑</div>
													 <#elseif com.sale_price??&&com.sale_price_xc??&&(com.sale_price_xc?number==com.sale_price?number)>
													 <div>${com.sale_price_xc}</div>
													 <#elseif com.sale_price??&&com.sale_price_xc??&&(com.sale_price_xc?number<com.sale_price?number)>
													 <div style="color:red">${com.sale_price_xc}↓</div>
													 </#if>
													 </strong></td>
													<td><strong>
													<#if com.sale_price??&&com.sale_price_tn??&&(com.sale_price_tn?number>com.sale_price?number)>
													 <div style="color:green">${com.sale_price_tn}↑</div>
													 <#elseif com.sale_price??&&com.sale_price_tn??&&(com.sale_price_tn?number==com.sale_price?number)>
													 <div>${com.sale_price_tn}</div>
													 <#elseif com.sale_price??&&com.sale_price_tn??&&(com.sale_price_tn?number<com.sale_price?number)>
													 <div style="color:red">${com.sale_price_tn}↓</div>
													 </#if>
													</strong></td>
													<td><strong>
													<#if com.sale_price??&&com.sale_price_tc??&&(com.sale_price_tc?number>com.sale_price?number)>
													 <div style="color:green">${com.sale_price_tc}↑</div>
													 <#elseif com.sale_price??&&com.sale_price_tc??&&(com.sale_price_tc?number==com.sale_price?number)>
													 <div>${com.sale_price_tc}</div>
													 <#elseif com.sale_price??&&com.sale_price_tc??&&(com.sale_price_tc?number<com.sale_price?number)>
													 <div style="color:red">${com.sale_price_tc}↓</div>
													 </#if>
													</strong></td>
													<td><strong>
													<#if com.sale_price??&&com.sale_price_qnr??&&(com.sale_price_qnr?number>com.sale_price?number)>
													 <div style="color:green">${com.sale_price_qnr}↑</div>
													 <#elseif com.sale_price??&&com.sale_price_qnr??&&(com.sale_price_qnr?number==com.sale_price?number)>
													 <div>${com.sale_price_qnr}</div>
													 <#elseif com.sale_price??&&com.sale_price_qnr??&&(com.sale_price_qnr?number<com.sale_price?number)>
													 <div style="color:red">${com.sale_price_qnr}↓</div>
													 </#if>
													</strong></td>
													
													<td class="center">
														<div class="action-buttons">
															<a  class="green bigger-140 show-details-btn" title="Show Details">
																<i class="ace-icon fa fa-angle-double-down"></i>
																<span class="sr-only">Details</span>
															</a>
														</div>
													</td>
													<td>
													<#if com.set_as_lowest??&& com.set_as_lowest?number==1>
														已设为产品起价
													<#else>
														<a title="执行" class="green" onclick="setAsLowest(this);"role="button"  data-toggle="modal">
															<i class="ace-icon fa fa-check bigger-120"></i>
										                </a>	
										            </#if>
													</td>
													<td align='center'>
														<div class="hidden-sm hidden-xs action-buttons">
															<a class="blue" onclick="showPriceList(this);" role='button'>
																<i class="ace-icon fa fa-search-plus bigger-130"></i>
															</a>
														</div>
													</td>
												</tr>
												
												<tbody class="detail-row"  style='display:none'>
													<tr style='background-color:pink'>
														<th colspan='2' style='background-color:pink'>属性</th>
														<th colspan='1' style='background-color:pink'>lmm</th>
														<th colspan='1' style='background-color:pink'>xc</th>
														<th colspan='1' style='background-color:pink'>tn</th>
														<th colspan='2' style='background-color:pink'>tc</th>
														<th colspan='6' style='background-color:pink'>qnr</th>
													</tr>
													<tr style='background-color:azure'>
														<th colspan='2' style='background-color:azure'>商品名称</th>
														<td colspan='1' style='background-color:azure'><#if com.commodity_name??>${com.commodity_name}</#if></td>
														<td colspan='1' style='background-color:azure'><#if com.commodity_name_xc??>${com.commodity_name_xc}</#if></td>
														<td colspan='1' style='background-color:azure'><#if com.commodity_name_tn??>${com.commodity_name_tn}</#if></td>
														<td colspan='2' style='background-color:azure'><#if com.commodity_name_tc??>${com.commodity_name_tc}</#if></td>
														<td colspan='6' style='background-color:azure'><#if com.commodity_name_qnr??>${com.commodity_name_qnr}</#if></td>
													</tr>
													<tr style='background-color:azure'>
														<th colspan='2' style='background-color:azure'>提前条件</th>
														<td colspan='1' style='background-color:azure'><#if com.sale_cond??>${com.sale_cond}</#if></td>
														<td colspan='1' style='background-color:azure'><#if com.sale_cond_xc??>${com.sale_cond_xc}</#if></td>
														<td colspan='1' style='background-color:azure'><#if com.sale_cond_tn??>${com.sale_cond_tn}</#if></td>
														<td colspan='2' style='background-color:azure'><#if com.sale_cond_tc??>${com.sale_cond_tc}</#if></td>
														<td colspan='6' style='background-color:azure'><#if com.sale_cond_qnr??>${com.sale_cond_qnr}</#if></td>
													</tr>
													<tr style='background-color:azure'>
														<th colspan='2' style='background-color:azure'>是否可退</th>
														<td colspan='1' style='background-color:azure'><#if com.refund_cond??>${com.refund_cond}</#if></td>
														<td colspan='1' style='background-color:azure'><#if com.refund_cond_xc??>${com.refund_cond_xc}</#if></td>
														<td colspan='1' style='background-color:azure'><#if com.refund_cond_tn??>${com.refund_cond_tn}</#if></td>
														<td colspan='2' style='background-color:azure'><#if com.refund_cond_tc??>${com.refund_cond_tc}</#if></td>
														<td colspan='6' style='background-color:azure'><#if com.refund_cond_qnr??>${com.refund_cond_qnr}</#if></td>
													</tr>
													<tr style='background-color:azure'>
														<th colspan='2' style='background-color:azure'>优惠</th>
														<td colspan='1' style='background-color:azure'><#if com.preferential_info??>${com.preferential_info}</#if></td>
														<td colspan='1' style='background-color:azure'><#if com.preferential_info_xc??>${com.preferential_info_xc}</#if></td>
														<td colspan='1' style='background-color:azure'><#if com.preferential_info_tn??>${com.preferential_info_tn}</#if></td>
														<td colspan='2' style='background-color:azure'><#if com.preferential_info_tc??>${com.preferential_info_tc}</#if></td>
														<td colspan='6' style='background-color:azure'><#if com.preferential_info_qnr??>${com.preferential_info_qnr}</#if></td>
													</tr>
												</tbody>
										</tbody>
										</#list>
										</#if>
									</table>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-xs-12">
							<button class="btn btn-info" data-toggle="modal" type="button" style="display:none;" id="update" data-target="#myModal"></button>
							<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
								   <div class="modal-dialog">
								      <div class="modal-content">
								         <div class="modal-header">
								            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
								                  ×
								            </button>
											选择时段:<label ><input type="text" id="config-demo" name="chooseTimeVO" class="form-control time" style="width:200px;height:32px;"></label>
											<button id="app_search" type="button"  onclick="replaceDate('7');" class="btn btn-white btn-sm">
											<span class="ace-icon icon-on-right bigger-110"></span>
												过去7天
											</button>
											<button id="app_search" type="button"  onclick="replaceDate('31');" class="btn btn-white btn-sm">
												<span class="ace-icon icon-on-right bigger-110"></span>
												过去31天
											</button>
											<button id="ajax_search" type="button" class="btn btn-pink btn-sm">
												<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
												Search
											</button>
								         </div>
								         <div class="modal-body">
								         	<div id="main" style="width: 550px;height:400px;"></div>
								         </div>
							     	</div>
								  </div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<input type="hidden" name="showproductcontextPath" value="${request.contextPath}"/> 
		<script type="text/javascript">
			if('ontouchstart' in document.documentElement) 
				document.write("<script src='${request.contextPath}/static/assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>
				
		<script src="${request.contextPath}/static/assets/js/bootstrap.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/jquery-ui.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/bootbox.js"></script>
		<script src="${request.contextPath}/static/assets/js/spin.js"></script>
		<!-- ace scripts -->
		<script src="${request.contextPath}/static/assets/js/ace-elements.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/ace.min.js"></script>
		<!-- validator scripts -->
		<script src="${request.contextPath}/static/assets/js/bootstrapValidator.min.js"></script>
		<!-- user scripts -->
		<script src="${request.contextPath}/static/assets/js/user/base.js"></script>
		
		<script src="${request.contextPath}/static/assets/js/moment.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/daterangepicker.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/echarts.min.js"></script>
		<script type="text/javascript">
		var showproductcontextPath = $("#showproductcontextPath").val();
		// 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));
     // 指定图表的配置项和数据
        var option = {
			title: {
				text: '历史抓取价格'
			},
			tooltip: {
				trigger: 'axis'
			},
			legend: {
				data:['lvmama','xc','tn','tc','qnr']
			},
			grid: {
				left: '3%',
				right: '4%',
				bottom: '3%',
				containLabel: true
			},
			toolbox: {
				feature: {
					saveAsImage: {}
				}
			},
			xAxis: {
				type: 'category',
				boundaryGap: true,
				data: []
			},
			yAxis: {
				type: 'value'
			},
			series: [
						{
							name:'lvmama',
							type:'line',
							stack: '价格',
							data:[]
						},
						{
							name:'xc',
							type:'line',
							stack: '价格',
							data:[]
						},
						{
							name:'tn',
							type:'line',
							stack: '价格',
							data:[]
						},
						{
							name:'tc',
							type:'line',
							stack: '价格',
							data:[]
						},
						{
							name:'qnr',
							type:'line',
							stack: '价格',
							data:[]
						}
					]

		};
       
		$("#ajax_search").click(function(){
			productId=$("#prodId").val();
			commodityId=$("#commodityId").val();
			chooseTime = $("#config-demo").val();
			$.ajax({
				url : showproductcontextPath+'/datashow/commodityPriceHistory',
				type : "GET",
				data : {
					productId:productId,
					commodityId:commodityId,
					chooseTime:chooseTime
				},
				success:function(data){
					lmmList=data.lmmList;	
					xcList=data.xcList;
					tnList=data.tnList;
					tcList=data.tcList;
					qnrList=data.qnrList;
					lmmPrice=[];
					xcPrice=[];
					tnPrice=[];
					tcPrice=[];
					qnrPrice=[];
					var xAxisDataf= dataScope(chooseTime.split(" - ")[0],chooseTime.split(" - ")[1]);
					option.xAxis.data = xAxisDataf;
					//对X轴进行遍历，将对应的Y轴填充数据
					for(var i=0;i<xAxisDataf.length;i++){
						//遍历lmm的价格表，并将对应时间的价格赋给相应Y轴
						if(lmmList!=null&&lmmList.length>0){
							for(var j=0;j<lmmList.length;j++){
								m=lmmList[j].sale_date.substring(4,6);
								d=lmmList[j].sale_date.substring(6,8);
								date=m+"-"+d;
								if(date==xAxisDataf[i]){
									lmmPrice[i]=lmmList[j].sale_price;
								}else if(lmmPrice[i]==null){
									lmmPrice[i]=0
								}
							}
						}else{
							lmmPrice[i]=0;
						}
						if(xcList!=null&&xcList.length>0){
							for(var j=0;j<xcList.length;j++){
								m=xcList[j].sale_date.substring(4,6);
								d=xcList[j].sale_date.substring(6,8);
								date=m+"-"+d;
								if(date==xAxisDataf[i]){
									xcPrice[i]=xcList[j].sale_price;
								}else if(xcPrice[i]==null){
									xcPrice[i]=0
								}
							}
						}
						if(tnList!=null&&tnList.length>0){
							for(var j=0;j<tnList.length;j++){
								m=tnList[j].sale_date.substring(4,6);
								d=tnList[j].sale_date.substring(6,8);
								date=m+"-"+d;
								if(date==xAxisDataf[i]){
									tnPrice[i]=tnList[j].sale_price;
								}else if(tnPrice[i]==null){
									tnPrice[i]=0
								}
							}
						}
						if(tcList!=null&&tcList.length>0){
							for(var j=0;j<tcList.length;j++){
								m=tcList[j].sale_date.substring(4,6);
								d=tcList[j].sale_date.substring(6,8);
								date=m+"-"+d;
								if(date==xAxisDataf[i]){
									tcPrice[i]=tcList[j].sale_price;
								}else if(tcPrice[i]==null){
									tcPrice[i]=0
								}
							}
						}
						if(qnrList!=null&&qnrList.length>0){
							for(var j=0;j<qnrList.length;j++){
								m=qnrList[j].sale_date.substring(4,6);
								d=qnrList[j].sale_date.substring(6,8);
								date=m+"-"+d;
								if(date==xAxisDataf[i]){
									qnrPrice[i]=qnrList[j].sale_price;
									
								}else if(qnrPrice[i]==null){
									qnrPrice[i]=0
								}
							}
						}
					}
					option.series[0].data = lmmPrice;
					option.series[1].data = xcPrice;
					option.series[2].data = tnPrice;
					option.series[3].data = tcPrice;
					option.series[4].data = qnrPrice;
					 // 使用刚指定的配置项和数据显示图表。
			        myChart.setOption(option);
					
				}
			});
		});
		
		setAsLowest=function(obj){
			commodity_id=$(obj).parents("tr").find(".tdCommodityId").text();
			prod_id=$("#prodId").val();
			bootbox.confirm("<strong style='font-size:15px;padding-left:200px'>是否确认设为产品起价？</strong>", function(result){
				if(result){
					$.ajax({
						url : showproductcontextPath+'/datashow/setAsLowest',
						type : "GET",
						data : {
							commodity_id:commodity_id,
							prod_id:prod_id
						},
						success:function(data){
							
						}
					});
				}
			});
			
		}
		
		function dataScope(value1, value2) {
            var getDate = function (str) {
                var tempDate = new Date();
                var list = str.split("/");
                tempDate.setFullYear(list[2]);
                tempDate.setMonth(list[0] - 1);
                tempDate.setDate(list[1]);
                return tempDate;
            }
            var date1 = getDate(value1);
            var date2 = getDate(value2);
            if (date1 > date2) {
                var tempDate = date1;
                date1 = date2;
                date2 = tempDate;
            }
            date1.setDate(date1.getDate());
            var dateArr = [];
            var i = 0;
            while (!(date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate() + 1)) {
                dateArr[i] = ((date1.getMonth() + 1) < 10 ? ('0' + (date1.getMonth() + 1)) : (date1.getMonth() + 1))+ "-" 
                        + (date1.getDate() < 10 ? ('0' + (date1.getDate())) : (date1.getDate()));
                i++;
                date1.setDate(date1.getDate() + 1);
            }
            return dateArr;
        }	
		$('.show-details-btn').on('click', function(e) {
			e.preventDefault();
			$(this).closest('tbody').next().toggle()
			$(this).find(ace.vars['.icon']).toggleClass('fa-angle-double-down').toggleClass('fa-angle-double-up');
		});
		showPriceList=function(obj){
			$("#update").click();
			chooseTime = $("#config-demo").val();
			
			commodityId=$(obj).parents("tr").find(".tdCommodityId").text();
			$("#commodityId").val(commodityId);
			productId=$("#prodId").val();
			commodityId=$("#commodityId").val();
			chooseTime = $("#config-demo").val();
			$.ajax({
				url : showproductcontextPath+'/datashow/commodityPriceHistory',
				type : "GET",
				data : {
					productId:productId,
					commodityId:commodityId,
					chooseTime:chooseTime
				},
				success:function(data){
					lmmList=data.lmmList;	
					xcList=data.xcList;
					tnList=data.tnList;
					tcList=data.tcList;
					qnrList=data.qnrList;
					lmmPrice=[];
					xcPrice=[];
					tnPrice=[];
					tcPrice=[];
					qnrPrice=[];
					var xAxisDataf= dataScope(chooseTime.split(" - ")[0],chooseTime.split(" - ")[1]);
					option.xAxis.data = xAxisDataf;
					for(var i=0;i<xAxisDataf.length;i++){
						if(lmmList!=null&&lmmList.length>0){
							for(var j=lmmList.length-1;j>=0;j--){
								m=lmmList[j].sale_date.substring(4,6);
								d=lmmList[j].sale_date.substring(6,8);
								date=m+"-"+d;
								if(date==xAxisDataf[i]){
									lmmPrice[i]=lmmList[j].sale_price;
								}else if(lmmPrice[i]==null){
									lmmPrice[i]=0;
								}
							}
						}else{
							lmmPrice[i]=0;
						}
						if(xcList!=null&&xcList.length>0){
							for(var j=xcList.length-1;j>=0;j--){
								m=xcList[j].sale_date.substring(4,6);
								d=xcList[j].sale_date.substring(6,8);
								date=m+"-"+d;
								if(date==xAxisDataf[i]){
									xcPrice[i]=xcList[j].sale_price;
								}else if(xcPrice[i]==null){
									xcPrice[i]=0;
								}
							}
						}
						if(tnList!=null&&tnList.length>0){
							for(var j=tnList.length-1;j>=0;j--){
								m=tnList[j].sale_date.substring(4,6);
								d=tnList[j].sale_date.substring(6,8);
								date=m+"-"+d;
								if(date==xAxisDataf[i]){
									tnPrice[i]=tnList[j].sale_price;
								}else if(tnPrice[i]==null){
									tnPrice[i]=0;
								}
							}
						}
						if(tcList!=null&&tcList.length>0){
							for(var j=tcList.length-1;j>=0;j--){
								m=tcList[j].sale_date.substring(4,6);
								d=tcList[j].sale_date.substring(6,8);
								date=m+"-"+d;
								if(date==xAxisDataf[i]){
									tcPrice[i]=tcList[j].sale_price;
								}else if(tcPrice[i]==null){
									tcPrice[i]=0;
								}
							}
						}
						if(qnrList!=null&&qnrList.length>0){
							for(var j=qnrList.length;j>=0;j--){
								m=qnrList[j].sale_date.substring(4,6);
								d=qnrList[j].sale_date.substring(6,8);
								date=m+"-"+d;
								if(date==xAxisDataf[i]){
									qnrPrice[i]=qnrList[j].sale_price;
									
								}else if(qnrPrice[i]==null){
									qnrPrice[i]=0;
								}
							}
						}
					}
					option.series[0].data = lmmPrice;
					option.series[1].data = xcPrice;
					option.series[2].data = tnPrice;
					option.series[3].data = tcPrice;
					option.series[4].data = qnrPrice;
					 // 使用刚指定的配置项和数据显示图表。
			        myChart.setOption(option);
					
				}
			});
			
		}
		function replaceDate(obj){
    		if(obj == '7'){
    			startDate = new Date(new Date().getTime()-7*1000*60*60*24);
	    		endDate = new Date(new Date().getTime()-1*1000*60*60*24);
    		}else if(obj == '31'){
    			startDate = new Date(new Date().getTime()-31*1000*60*60*24);
	    		endDate = new Date(new Date().getTime()-1*1000*60*60*24);
    		}
		 	var dateStr = dateFormat(startDate) + " - " + dateFormat(endDate);
		    $(".time").val(dateStr);
    	}
		function dateFormat(date){
    		var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    var currentdate = month + "/" + strDate + "/" + date.getFullYear();
		    return currentdate;
    	}
		$('.time').daterangepicker(
				{
					startDate: new Date(new Date().getTime()-31*1000*60*60*24),
				    endDate: new Date(new Date().getTime()),
					showDropdowns : true,
					showWeekNumbers : false,
					timePicker : false,
					timePicker12Hour : false,
					ranges : {
						/* '昨日': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
		            	'过去7天': [moment().subtract(7, 'days'), moment().subtract(1, 'days')],
		                '过去31天': [moment().subtract(31, 'days'), moment().subtract(1, 'days')] */
					},
					opens : 'right',
					buttonClasses : [ 'btn btn-default' ],
					applyClass : 'btn-small btn-pink blue',
					cancelClass : 'btn-small',
					format : 'yyyy-MM-dd',
					separator : ' to ',
					locale : {
						applyLabel : '确定',
						cancelLabel : '取消',
						fromLabel : '起始时间',
						toLabel : '结束时间',
						customRangeLabel : '自定义',
						daysOfWeek : [ '日', '一', '二', '三', '四', '五',
								'六' ],
						monthNames : [ '一月', '二月', '三月', '四月', '五月',
								'六月', '七月', '八月', '九月', '十月', '十一月',
								'十二月' ],
						firstDay : 1
					}
				},
				function(start, end, label) {//格式化日期显示框

					$('.time').html(
							start.format('yyyy-MM-dd') + ' - '
									+ end.format('yyyy-MM-dd'));
				});
		</script>
	</body>
</html>